const express = require('express');
const app = express();
const fs = require('fs');
fs.readdir('./server/cloud_functions/', function(res, file){
    // console.log(res, file);
    file.forEach(item => {
        if(fs.lstatSync(`./server/cloud_functions/${item}`).isDirectory()){
            app.get(`/api/${item}`, (req, res, next)=>{
                // console.log(item);
                const itemFn = require('./cloud_functions/' + item + '/index').main;
                // console.log(itemFn)
                itemFn(req.query).then(result => {
                    console.log(result)
                    res.send(result);
                })
            })
        }
    })
});
app.listen(8080, () => {
    console.log('server start');
})